import javax.swing.JApplet;
import javax.swing.event.MouseInputListener;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;

public class AhaChange extends Game implements Runnable
{
	Image pic1,pic2,currentPic;
	Thread myThread; 
	boolean gray = false;
	Image offscreenImage;		
	Graphics offscreenGraphics;	
	
	//added a comment
	
//	JButton start = new JButton ();
	public AhaChange(Image p1,Image p2)
	{
		pic1= p1;
		pic2= p2;
//		setSize(pic2.getWidth(this),pic2.getHeight(this));
		setSize(1000,1000);  // worry about size later
		
		myThread = new Thread(this);
		myThread.start();
	}

	public void paintComponent(Graphics g)
	{
		offscreenImage = createImage(getWidth(),getHeight());
		offscreenGraphics = offscreenImage.getGraphics();	
		Graphics2D g2 = (Graphics2D)offscreenGraphics; ;
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		
		if(gray)
		{
			g2.setColor(Color.RED);
			g2.fillRect(0,0,getWidth(),getHeight());
			
		}
		else
		{
			g2.drawImage(currentPic,0,0,this);
		}
		g.drawImage(offscreenImage,0,0,this);
		
	}
	
	public void run() 
	{
		currentPic=pic1;
		repaint();
		try
		{
			myThread.sleep(3000);	 //leave pic1 for some time
		}
		catch(Exception e)
		{
			
		}
		gray=true;
		repaint();
		
		try
		{
			myThread.sleep(4000);	//leave gray for some time
		}
		catch(Exception e)
		{
			
		}
		gray=false;
		currentPic=pic2;
		repaint();
		
		
	}
	
}